<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
<script>
    function getResult(pattern = '', s = '') {
        if(!pattern || !s){
            return false;
        }
        // 得到两个数组
        const patternArr = pattern.split('')
        const sArr = s.split(' ')
        const map = new Map()
        // true表示正常的
        let result = true;
        const resultArr = []
        // 判断位数不相等
        if(patternArr.length !== sArr.length){
            return false;
        }
        // 判断位数相等
        patternArr.map((p, pIndex) => {
            sArr.map((s, sIndex) => {
                if (pIndex === sIndex) {
                    // 有key
                    if (map.has(p)) {
                        // 是否key和之前设置进去的value是否相同
                        result = s !== map.get(p) ? false : true;
                    } else {
                        // 没有key,判断value是否已经在map中存在了
                       result =!Array.from(new Set(map.values())).includes(s);
                       if(result){
                           map.set(p, s);
                       }
                    }
                    resultArr.push(result)
                }
            })
        })
        return !resultArr.includes(false)
    }

    console.log(getResult('abba','dog cat cat fish'));
</script>
</body>
</html>